Skip to main content

Concept guide

Explanations, reading order, and protocol context.

Long-form reading
Section guide

v4 Fee Structure Guide

Overview of Fee Types​

This page describes fee behavior in the current FewToken + Uniswap v4 integration environment. It should be read as technical integration guidance, not as documentation for a separate native v4 AMM.

In this v4 integration stack, there are three main types of fees to understand:

  • LP Fee: Fees allocated to liquidity providers
  • Protocol Fee: Fees collected by the protocol
  • Swap Fee: Total fee paid by swappers (calculated by applying protocol fee and LP fee sequentially)

LP Fees​

LP fees are set by the pool initializer at pool creation and may be static or dynamic.

Fee Range:

  • Maximum LP Fee: 100%
  • Minimum LP Fee: 0%
  • Granularity: Fees are set at pip-level precision

Static LP Fees​

  • Immutable once set during pool initialization
  • Unlimited fee options in v4-style pools
  • Integrators should confirm the selected LP fee from the pool configuration instead of assuming fixed fee tiers

Dynamic LP Fees​

Dynamic fees offer more flexibility and real-time adjustability:

  • A dynamic fee pool signals this capability by setting its LP fee to 0x800000 (where the first bit = 1)
  • Only the pool's hook can update the dynamic fee—no additional permissions required
  • A hook cannot update fees if the pool's fee is not set to 0x800000

Protocol Fees​

Protocol fees are configured per pool with the following characteristics:

  • Controlled by the protocol fee controller (set by the pool manager owner)
  • Maximum protocol fee: 0.1% (1,000 pips)
  • Granularity: Fees are set at pip-level precision (not basis points)
  • Unit conversion: 1 basis point = 100 pips
  • Directional fees: Separate fees can be set for:
    • token0 → token1 swaps
    • token1 → token0 swaps

Swap Fees​

Sequential Fee Application​

In this v4 integration stack, the swap fee is the effective total fee after applying both protocol and LP fees sequentially.

Application Order​

  1. Protocol fee applied first to the input amount
  2. LP fee applied second to the remaining input (after protocol fee deduction)

Impact on LP Fee Share:

Note that this sequential application means introducing or increasing protocol fees will reduce the LP fee share even if swap volume remains constant, since LP fees are calculated on a smaller base amount.

Fee Cap​

  • Total swap fee capped at 100% of input amount
  • Important: If swap fee = 100%, exact output swaps become impossible (entire input consumed by fees)

Fee Calculation Formula​


// Method 1: Sequential application
uint256 swapFee = protocolFee + (lpFee * (1_000_000 - protocolFee)) / 1_000_000; (rounded up)

// Method 2: Mathematically equivalent
uint256 swapFee = protocolFee + lpFee - (protocolFee * lpFee) / 1_000_000;

Mathematical Derivation​

Starting with input amount:

amountIn

Step 1: Protocol fee takes:

amountIn × (protocolFee / 1_000_000)

Step 2: Remaining after protocol fee:


amountIn × (1 - protocolFee / 1_000_000)

Step 3: LP fee applies to remaining:

lpFee × (remaining amount)

Final formula:

swapFee = protocolFee + (lpFee × (1 - protocolFee / 1_000_000))

Which simplifies to:

swapFee = protocolFee + lpFee - (protocolFee × lpFee) / 1_000_000

Example Calculation​

Given:

  • protocolFee = 50 pips → 0.005%
  • lpFee = 3000 pips → 0.30%

Calculation:

swapFee = 50 + 3000 - (50 × 3000) / 1_000_000
= 50 + 3000 - 150 / 1_000_000
= 50 + 3000 - 0.15
= 3049.85 pips

Result: 3049.85 pips = 0.304985% total swap fee


Key Takeaways​

  • Sequential application: Protocol fees are deducted first, then LP fees apply to the remainder
  • Dynamic flexibility: v4 introduces unlimited static fee tiers and dynamic fee capabilities
  • Directional control: Protocol fees can differ by swap direction
  • Fee interaction: The combined effect is slightly less than simple addition due to sequential application